//
//  GJNumberAnnotationView.m
//  xmgjAppFront
//
//  Created by ZekiMini on 2020/8/31.
//  Copyright © 2020 guojutech. All rights reserved.
//

#import "GJNumberAnnotationView.h"
#import "GJNumberAnnotationCallOut.h"



@interface GJNumberAnnotationView ()
@property (nonatomic, strong)GJNumberAnnotationCallOut *calloutView;
@end

static const CGFloat kCalloutWidth = 44;
static const CGFloat kCalloutHeight = 60;

@implementation GJNumberAnnotationView



- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
  self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
  if (self) {
    
  }
  return self;
}
 


- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
  [super setSelected:selected animated:animated];
  if (self.calloutView == nil)
  {
      self.calloutView = [[GJNumberAnnotationCallOut alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
      self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                           + 20);
  }
  self.calloutView.numberText = self.numberText;
  self.calloutView.regionText = self.regiontext;
  CGFloat width =  [self.numberText widthForFont:kMediumSystemFontOfSize(14)] + 30;
  CGFloat regionWidth =  [self.regiontext widthForFont:kSystemFontOfSize(10)] + 30;
  
  if (width <= regionWidth) {
    width = regionWidth;
  }
  if (width <= kCalloutWidth) {
    width = kCalloutWidth;
  }
  if (width <kCalloutWidth) {
    width = kCalloutWidth;
  }
  [self.calloutView setFrame:CGRectMake(0, 0, width, kCalloutHeight)];
  [self.calloutView setNeedsDisplay];
  [self addSubview:self.calloutView];
}

#pragma mark -- setter
- (void)setNumberText:(NSString *)numberText{
  _numberText = numberText;
  
}
- (void)setRegiontext:(NSString *)regiontext{
  _regiontext = regiontext;
}

//- (GJNumberAnnotationCallOut *)calloutView{
//  _calloutView = [[GJNumberAnnotationCallOut alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
//  _calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
//                                       + 20);
//  return _calloutView;
//}

@end
